home *** CD-ROM | disk | FTP | other *** search
- /* test.c
- *
- * test for malloc heap trash debugger
- */
-
- #include <malloc.h>
-
- main()
- {
-
- int i;
- char * memory[ 100 ];
-
- #if MDB_DEBUG
- /* THIS DOESN'T NEED TO BE DONE IF YOU DO A "setenv DB_CHECK ON" */
- extern int db_check_on;
- db_check_on = 1;
- #endif
-
- #if CLIBS_DEBUG
- mallopt( M_DEBUG, 1 );
- #endif
-
- /* allocate 100 segments of memory */
- for ( i = 0; i < 100; i ++ ) {
-
- memory[ i ] = malloc( i );
-
- }
-
- /* deallocate half of em */
- for ( i = 0; i < 50; i++ ) {
-
- free( memory[ i * 2 ] );
-
- }
-
- printf( "OK so far - lets detect one ! %x !\n", ( memory[ 49 ] - 2 ) );
-
- * ( memory[ 49 ] - 2 ) = 0; /* Trash the heap */
- * ( memory[ 49 ] - 10 ) = 0; /* And again */
-
- for ( i = 0; i < 50; i++ ) {
-
- printf( "%d\n", i );
- free( memory[ 1 + i * 2 ] );
-
- }
-
- printf( "Bummer - didn't notice anything wrong !! Error !!\n" );
- }
-